﻿using System;
using System.Windows.Forms;
namespace Moonlite.UI.Shell.Controls
{
    public sealed class ShortcutManager
    {
        private ShortcutCollection shortcuts = new ShortcutCollection();
        private Control control;
        public Control Control
        {
            get { return control; }
            set
            {
                if (control != null) control.KeyUp -= OnControlKeyUp;
                control = value;
                if (control != null) control.KeyUp += OnControlKeyUp;
            }
        }
        public ShortcutCollection Shortcuts
        {
            get { return shortcuts; }
        }
        private void OnControlKeyUp(object sender, KeyEventArgs e)
        {
            foreach (Shortcut shortcut in shortcuts)
            {
                if (e.KeyCode == shortcut.Key && e.Shift == shortcut.Shift && e.Control == shortcut.Control && e.Alt == shortcut.Alt)
                {
                    shortcut.Action.Invoke();
                }
            }
        }
        public ShortcutManager() { }
        public ShortcutManager(Control control)
        {
            this.control = control;
        }
    }
}
